package com.yonyou.pmclouds.organization.mapper;

import com.yonyou.pmclouds.basecom.dao.BaseMapper;
import com.yonyou.pmclouds.organization.entity.OrgAndRoleVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

public interface OrgAndRoleMapper extends BaseMapper<OrgAndRoleVO> {

    @Select("select pk_org_and_role, pk_organization, pk_role, pk_src, is_tenant, change_flag from pm_organdrole where pk_tenant = #{pkTenant} and pk_role in (${pkRoles}) and dr = 0 ")
    OrgAndRoleVO[] getOrgByRole(@Param("pkTenant") String pkTenant, @Param("pkRoles") String pkRoles);

    OrgAndRoleVO[] getByRoles(@Param("pkTenant") String pkTenant, @Param("pkRoles") String pkRoles);

    @Select("select pk_org_and_role, pk_organization, pk_role, pk_src, change_flag from pm_organdrole where pk_tenant = #{pkTenant} and pk_organization in (${pkOrganizations}) and dr = 0 ")
    OrgAndRoleVO[] getRoleByOrg(@Param("pkTenant") String pkTenant, @Param("pkOrganizations") String pkOrganizations);

    @Select("select pk_org_and_role, pk_organization, pk_role from pm_organdrole where pk_tenant = #{pkTenant} and dr = 0 ")
    OrgAndRoleVO[] getRoleList(@Param("pkTenant") String pkTenant);

    @Select("select pk_org_and_role, pk_organization, pk_role, change_flag, pk_src from pm_organdrole where pk_tenant = #{pkTenant} and pk_role = #{pkRole} and pk_organization in (${pkOrganizations}) and dr = 0 ")
    OrgAndRoleVO[] getListByOrgAndRole(@Param("pkTenant") String pkTenant, @Param("pkOrganizations") String pkOrganizations, @Param("pkRole") String pkRole);

    @Select("select pk_org_and_role, pk_organization, pk_role, change_flag, pk_src from pm_organdrole where pk_tenant = #{pkTenant} and pk_role in (${pkRoles}) and is_tenant = 'Y' and dr = 0 ")
    OrgAndRoleVO[] getTenantRoleList(@Param("pkTenant") String pkTenant, @Param("pkRoles") String pkRoles);

    @Select("select count(*) from pm_organdrole where pk_tenant = #{pkTenant} and pk_role in (${pkRoles}) and is_tenant = 'Y' and dr = 0 ")
    Integer countTenantRole(@Param("pkTenant") String pkTenant, @Param("pkRoles") String pkRoles);

    @Select("select pk_org_and_role, pk_organization, pk_role, change_flag from pm_organdrole where pk_tenant = #{pkTenant} and pk_organization = #{pkOrganization} and dr = 0 ")
    OrgAndRoleVO[] getListByOrg(@Param("pkTenant") String pkTenant, @Param("pkOrganization") String pkOrganization);

    String[] queryOrgIdsByRoles(@Param("pkTenant") String pkTenant, @Param("pkRoles") String[] pkRoles);
}
